package xyz.zhno.mall.common.web.util;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet工具类
 * @author zh_o
 */
public class ServletUtils {

    private static final ServletRequestAttributes ATTRS = (ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes());

    /**
     * 获取当前请求对象
     * @return 请求对象
     */
    public static HttpServletRequest getRequest() {
        return ATTRS.getRequest();
    }

    /**
     * 获取响应对象
     * @return 响应对象
     */
    public static HttpServletResponse getResponse() {
        return ATTRS.getResponse();
    }

    /**
     * 获取session
     * @return session对象
     */
    public static HttpSession getSession() {
        return getRequest().getSession();
    }

}
